﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Commonlib;
namespace AlbonWeb.Manager.ClientManager
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BLL.UserBLL userbll = new BLL.UserBLL();
                if (!userbll.isAdmin)
                {
                    userName.Text = User.Identity.Name;
                    userName.Enabled = false;
                }
                ViewState["limit"] = "where 1=1";
                bindClient();
            }
        }
        protected void bindClient()
        {
            if (clientName.Text.Trim() != "")
            {
                ViewState["limit"] += " and clientName like '%" + clientName.Text.Trim() + "%'";
            }
            if (userName.Text.Trim() != "")
            {
                ViewState["limit"] += " and userName like '%" + userName.Text.Trim() + "%'";
            }
            string cmdstr = "select count(*) from Client " + ViewState["limit"].ToString();
            AspNetPager1.RecordCount =int.Parse(SqlHelper.ExecuteScalar(SqlHelper.SqlConnectionString,CommandType.Text,cmdstr,null).ToString());
            SqlParameter[] parameters = new SqlParameter[]{
                new SqlParameter("@tablename","Client"),
                new SqlParameter("@startIndex",AspNetPager1.StartRecordIndex),
                new  SqlParameter("@endIndex",AspNetPager1.EndRecordIndex),
                new SqlParameter("@limit",ViewState["limit"].ToString()),
                new SqlParameter("@orderby","createDate desc")
            };
            SqlHelper.BindRepeater(repMain, SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "netpager", parameters);
        }

        protected void btnSearch_Click(object sender, ImageClickEventArgs e)
        {
            ViewState["limit"]="where 1=1";
            bindClient();
        }

        //换页
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            bindClient();
        }
    }
}